﻿@model Nop.Web.Models.Common.LanguageSelectorModel
@if (Model.AvailableLanguages.Count > 1)
{
    if (Model.UseImages)
    {
    <ul class="languagelist">
        @foreach (var lang in Model.AvailableLanguages)
        {
            <li><a href="@Url.Action("setlanguage", "common", new { langid = lang.Id })" title="@lang.Name">
                <img title='@lang.Name' alt='@lang.Name' @(lang.Id == Model.CurrentLanguage.Id ? " class=selected" : null)
                 src="@Url.Content("~/Content/Images/flags/" + @lang.FlagImageFileName) " />
            </a></li>
        }
    </ul>
    }
    else
    {

        var languages = Model.AvailableLanguages.Select(x => new SelectListItem
        {
            Text = x.Name,
            Value = x.Id.ToString(),
            Selected = x.Id.Equals(Model.CurrentLanguage.Id)
        });
    
    @Html.DropDownList("customerlanguage", languages)
            
    <script type="text/javascript">
        $(document).ready(function () {
            $("#customerlanguage").change(onLanguageChanged);
        });

        function onLanguageChanged() {
            var selectedCustomerLanguage = document.getElementById('customerlanguage');
            var selectedLanguageId = selectedCustomerLanguage.options[selectedCustomerLanguage.selectedIndex].value;
            var changeLanguageActionUrl = '@Url.Action("SetLanguage", "Common", new { langid = "languageplaceholder" })';
            changeLanguageActionUrl = changeLanguageActionUrl.replace("languageplaceholder", selectedLanguageId);
            setLocation(changeLanguageActionUrl);
        }
    </script>
        
    }
}